﻿@using WSS.Pub
@{
    ViewBag.Title = "列表";
}
<div class="container">
    <ol class="breadcrumb">
        <li><a href="/adm/usercenter">用户中心</a></li>
        <li class="active">@(ViewBag.HOSPITAL_NAME) 职工列表</li>
    </ol>

    <div class="panel panel-primary">
        <div class="panel-heading">职工信息</div>
        <div class="panel-body form-inline">

            <label>姓名：<input id="sch_username" type="text" style="width: 120px;" /></label>

            @Html.MyButton("btn_sch", "搜索")

            @Html.MyButton("btn_add", "新增", "primary")

            @Html.MyButton("btn_edit", "编辑", "danger")

            @Html.MyButton("btn_imp", "导入", "info")
        </div>

        <table id="maingrid"></table>
        <div class="panel-footer">
            <ul id="page1"></ul>
        </div>
    </div>
</div>

<div id="hid_add_form" class="hide formpanel">
    <form id="form1">
        <div>
            <label>
                工号:
                @Html.Hidden("HOSP_ID")
                @Html.Hidden("USER_ID")
                <input name="USER_NO" id="USER_NO" class="notnull" /></label>
            <label>
                姓名:
                <input name="USER_NAME" id="USER_NAME" class="notnull" /></label>
        </div>
        <div>
            <label>
                性别:
            <select name="USER_GENDER" class="notnull">
                <option value="1">男</option>
                <option value="2">女</option>
            </select>
            </label>
            <label>
                电话:
                <input name="USER_PHONE" /></label>
        </div>
        <div>
            <label>
                邮箱:
                <input name="USER_EMAIL" /></label>
            <label>
                QQ:
                <input name="USER_QQ" /></label>
        </div>
        <div>
            <label>
                启用状态:
                <select name="FLAG_LOGIN">
                    <option value="1">启用</option>
                    <option value="0">禁用</option>
                </select>
            </label>
            <label>
            </label>
        </div>
    </form>
</div>

@section script
{

    <script src="@Url.Content("~/Scripts/plugins/bootstrap-paginator.min.js")"></script>
    <script src="@Url.Content("~/Scripts/plugins/jquery.grid.js")"></script>

    <script type="text/javascript">
        $(function () {

            $("#btn_sch").click(function () {
                sch();
            });

            function resetForm() {
                mainfn.removeReadonly("USER_NO");
                $("#form1").get(0).reset();
            }

            $("#btn_add").click(function () {
                resetForm();
                var html = $("#hid_add_form").addClass("show").removeClass("hide");
                mainfn.dialog("添加职工 - @(ViewBag.HOSPITAL_NAME)", html, save, false);
            });

            $("#btn_edit").click(function () {
                var row = $("#maingrid").bootgrid("getGridSelRow");
                if (row) {
                    bindForm(row);
                }
            });

            $("#btn_imp").click(function () {
                window.document.location.href = "/usercenter/importuser/@(ViewBag.HOSP_ID)";
            });

            function bindForm(row) {
                mainfn.setReadonly("USER_NO");
                mainfn.loadForm($("#form1"), row);
                var html = $("#hid_add_form").addClass("show").removeClass("hide");
                mainfn.dialog("编辑职工 - @(ViewBag.HOSPITAL_NAME)", html, save, false);
            }

            function save() {

                if (mainfn.checkForm($("#form1"))) {
                    return false;
                }

                var s = $("#form1").serialize();
                var url = "/usercenter/adduser";
                if ($("#USER_ID").val()) {
                    url = "/usercenter/updateuser";
                }
                $.post(url, s, function (msg) {
                    mainfn.msg(msg.msg);
                    if (msg.flag) {
                        sch();
                    }
                });

                $("#form1").get(0).reset();

                return true;
            }

            function sch() {
                $("#maingrid").bootgrid("setGridParam", { username: $("#sch_username").val() });
                $("#maingrid").bootgrid("reloadGrid", { page: 1 });
            }

            function init(parameters) {

                $("#maingrid").bootgrid({
                    url: '/usercenter/list/@(ViewBag.HOSP_ID)',
                    pager: "page1",
                    headers: ["ID", "HOSP_ID", "工号", "姓名", "性别", "手机", "QQ", "邮箱", "帐号状态"],
                    cols: [
                        { id: 'USER_ID', hidden: true },
                        { id: 'HOSP_ID', hidden: true },
                        { id: 'USER_NO' },
                        { id: 'USER_NAME' },
                        { id: 'USER_GENDER', formatter: { type: "select", fmt: { "1": "男", "2": "女" } } },
                        { id: 'USER_PHONE' },
                        { id: 'USER_QQ' },
                        { id: 'USER_EMAIL' },
                        { id: 'FLAG_LOGIN', formatter: { type: "select", fmt: { "1": "启用", "0": "<span style='color:red;'>禁用</span>" } } }
                    ],
                    ondbclick: function (e, id, row) {
                        bindForm(row);
                    }
                });

            }

            init();
        });
    </script>
}